import java.util.HashMap;
import java.util.HashSet;
import java.util.Stack;

public class 有效的括号 {

    public static void main(String[] args) {
        System.out.println(isValid("(("));
    }

    public static boolean isValid(String s) {
        if (s.length() == 1) return false;
        HashSet<Character> characters = new HashSet<>();
        characters.add('(');
        characters.add('[');
        characters.add('{');
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (characters.contains(s.charAt(i))) {
                stack.add(s.charAt(i));
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                Character top = stack.peek();
                if (Math.abs(top - s.charAt(i)) > 2) {
                    return false;
                } else {
                    stack.pop();
                }
            }
        }
        return stack.isEmpty();
    }
}
